package com.kly.enums;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;


/**
 * 支付类型
 * @author linqu
 */
public enum PayTypeEnum {
    /**
     * 资金流入
     */
    REPAY(1, "REPAY"),
    /**
     * 资金流出
     */
    PAY(2, "PAY"),
    /**
     * 支付通知增加订单号
     */
    ADD_ORDER_NO(3, "ADD_ORDER_NO"),
    ;


    private Integer code;
    private String name;

    PayTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public PayTypeEnum setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getName() {
        return name;
    }

    public PayTypeEnum setName(String name) {
        this.name = name;
        return this;
    }

    public static PayTypeEnum getEnumByCode(Integer code) {

        if (Objects.isNull(code)) {
            return null;
        }

        PayTypeEnum payTypeEnum = null;

        for (PayTypeEnum p : PayTypeEnum.values()) {
            if (p.getCode().equals(code)) {
                payTypeEnum = p;
            }
        }
        return payTypeEnum;
    }


    public static List<PayTypeEnum> getPaymentChannelEnumList() {
        List<PayTypeEnum> payGatewayEnumList = new ArrayList<>();

        for (PayTypeEnum paymentChannelEnum : PayTypeEnum.values()) {
            payGatewayEnumList.add(paymentChannelEnum);
        }

        return payGatewayEnumList;
    }
}
